﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileDuplicateRemover.Core;
using Useful;

namespace FileDuplicateRemover.Test.WinForm
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DirectoryEntity de = null;
            using (EntityTreeBuilder eb = new EntityTreeBuilder("c:\\FDR_TEST"))
            {
                de = eb.Create();
            }

            DuplicateEntityDescriptionList duplicateEntityList = new DuplicateEntityDescriptionList();
            EntityTreeWalker ec = new EntityTreeWalker();

            ec.Walk(de, duplicateEntityList.Add);

            IEnumerable<DuplicateEntityDescription> sortedList = duplicateEntityList.OrderBy(i => i.SomeEntity.Length);

            //List<DuplicateEntityDescription> list = duplicateEntityList.ToList();



            SortableBindingList<GridItem> sbList = new SortableBindingList<GridItem>();

            foreach (DuplicateEntityDescription ded in sortedList)
            {
                sbList.Add(new GridItem(ded, ded.SomeEntity));

                foreach(BaseEntity be in ded)
                {
                    if (be != ded.SomeEntity)
                        sbList.Add(new GridItem(ded, be));
                }
            }

            //BindingList<DuplicateEntityDescription> bList = new BindingList<DuplicateEntityDescription>(list);

            bindingSource1.DataSource = sbList;

            //bindingSource1.ResetBindings(true);

            Text =  grid.Rows.Count.ToString();
            //Text = bindingSource1.Count.ToString();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            grid.AutoGenerateColumns = true;

            grid.DataSource = bindingSource1;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            grid.GroupRows("ID");
        }
    }
}
